#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <unordered_map>
#include <vector>
#include <set>
#include <queue>

using namespace std;
using LL = long long;
using PII = pair<int, int>;
const int N = 2e5 + 10;
struct Seg{
    int a, b, c;

    bool operator< (Seg& w) const{
        return c > w.c;
    }
}seg[N];


int n, m;
int p[N];

int find(int x){
    if(x != p[x]){
        p[x] = find(p[x]);
    }
    return p[x];
}

int main(){
#ifdef LOCALFLAG
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif


    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> n >> m;
    for(int i = 1; i <= n * 2; i ++) p[i] = i;

    for(int i = 0; i < m; i ++) cin >> seg[i].a >> seg[i].b >> seg[i].c;
    sort(seg, seg + m);

    for(int i = 0; i < m; i ++){
        int a = seg[i].a, b = seg[i].b, c = seg[i].c;
        
        if(find(a) == find(b) || find(a + n) == find(b + n)){
            cout << c << '\n';
            exit(0);
        }

        p[find(a)] = find(b + n);
        p[find(a + n)] = find(b);
    }

    cout << 0 << '\n';

    return 0;
}